package com.api.controller.auth;

import com.alibaba.fastjson.JSON;
import com.api.annotation.AuthToken;
import com.api.controller.BaseController;
import com.api.service.BaseService;
import com.api.service.auth.PermissionService;
import com.api.service.log.LogUserService;
import com.api.util.AjaxResult;
import com.api.util.LogUtil;
import com.api.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @packageName: com.api.controller.auth
 * @name: PermissionController
 * @description:
 * @author: 董定卓
 * @dateTime: 2019/6/19 14:34
 */
@RestController
@RequestMapping("/permission")
public class PermissionController extends BaseController {

    @Autowired
    PermissionService service;

    @Autowired
    LogUserService logUserService;

    @Override
    protected BaseService getService() {
        return service;
    }

    /**
     * 权限分页列表
     *
     * @param map
     * @param page
     * @param limit
     * @return
     */
    @PostMapping("/page")
    @Override
    @AuthToken
    public AjaxResult page(@RequestParam Map<String, Object> map, @RequestParam(value = "limit", defaultValue = "10") int limit, @RequestParam(value = "page", defaultValue = "1") int page) {
        Map<String, Object> logUserMap = LogUtil.addUserLog(UserUtil.getUserDetail().getId(), "/permission/page", JSON.toJSONString(map));
        logUserService.add(logUserMap);
        return super.page(map, limit, page);
    }

}
